package com.xmutca.core.dubbo;

import com.xmutca.core.common.Receipt;
import com.xmutca.core.common.Result;

import java.io.Serializable;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-07-13 12:59
 */
public class ServiceMock implements Serializable {

    public <T extends Result> T mock(Class<T> clazz) {
        try {
            T result = clazz.newInstance();
            result.setMessage("请求超时或者网络错误, 服务容错处理, 请稍后重试~");
            result.setStatus(Result.Status.TIMEOUT);

            return result;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return (T) new Result<>(Result.Status.TIMEOUT, "请求超时或者网络错误, 服务容错处理, 请稍后重试~");
    }
}
